package com.cipta.lomob.adapter;

import java.util.ArrayList;

import com.cipta.lomob.R;
import com.cipta.lomob.model.ItemVideo;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterHomeTimeline extends BaseAdapter{
	
	Activity activity;
	ArrayList<ItemVideo> listItem;
	LayoutInflater inflater;
	
	public AdapterHomeTimeline(Activity activity, ArrayList<ItemVideo> listItem) {
		// TODO Auto-generated constructor stub
		this.activity = activity;
		this.listItem = listItem;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listItem.size();
	}

	@Override
	public Object getItem(int pos) {
		return this.listItem.get(pos);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View view = arg1;
		ViewHolder holder = null;
		
		if (view == null) {
			view = inflater.inflate(R.layout.inf_item_home_timeline, null);
			holder = new ViewHolder();
			holder.txtFollowers = (TextView)view.findViewById(R.id.txt_inf_item_home_timeline_total_followers);
			holder.txtWatching = (TextView)view.findViewById(R.id.txt_inf_item_home_timeline_total_watching);
			holder.txtTitle = (TextView)view.findViewById(R.id.txt_inf_item_home_timeline_title);
			holder.txtUsername = (TextView)view.findViewById(R.id.txt_inf_item_home_timeline_username);
			holder.imgItem = (ImageView)view.findViewById(R.id.inf_img_item_home_timeline);
			view.setTag(holder);
		} else {
			holder = (ViewHolder)view.getTag();
		}
		
		holder.imgItem.setImageResource(listItem.get(arg0).getThumbnails());
		holder.txtFollowers.setText("Followers "+listItem.get(arg0).getUsers().getTotalFollowers());
		holder.txtWatching.setText("Watching "+listItem.get(arg0).getTotalWatching());
		holder.txtUsername.setText(listItem.get(arg0).getUsers().getName());
		holder.txtTitle.setText(listItem.get(arg0).getTitle());
		
		return view;
	}
	
	static class ViewHolder{
		ImageView imgItem;
		TextView txtUsername, txtTitle, txtFollowers, txtWatching;
	}
}
